package com.sykj.service.impl;

import com.sykj.service.WeChatService;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

import java.util.TreeSet;

/**
 * @program: BeautyClub
 * @description: 公众号配置token
 * @author: qiaoli
 * @create: 2020-07-24 14:35
 */
@Service
public class WeChatServiceImpl implements WeChatService {
    @Override
    public Boolean verifyInfo(String signature, String timestamp, String nonce, String token) {
        TreeSet<String> set = new TreeSet<String>();
        set.add(token);
        set.add(timestamp);
        set.add(nonce);
        StringBuilder sBuilder = new StringBuilder();
        for (String item : set) {
            sBuilder.append(item);
        }
        String sign = DigestUtils.sha1Hex(sBuilder.toString());
        return signature.equalsIgnoreCase(sign);

    }
}
